from django_filters.rest_framework import DjangoFilterBackend
from rest_framework.viewsets import ModelViewSet
from .serializer import GoodSerializer, GoodCategorySerializer
from .models import Goods, GoodsCategory
from common.MyPage import MyPageNumberPagination


# Create your views here.
class GoodViewSet(ModelViewSet):
    queryset = Goods.objects.all()
    serializer_class = GoodSerializer
    pagination_class = MyPageNumberPagination
    filter_backends = [DjangoFilterBackend]
    # filterer_fields = ['name', 'price']  # 有问题，用下面的s
    filterset_fields = ['price']


class GoodCategoryViewSet(ModelViewSet):
    queryset = GoodsCategory.objects.all()
    serializer_class = GoodCategorySerializer
    pagination_class = MyPageNumberPagination
